<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/2/14
 * Time: 15:43
 */

namespace app\admin\controller;
use think\Db;
use think\Request;

class Agreement extends Base
{
    /**
     * @return mixed|\think\response\Json
     * 编辑用户注册协议
     */
    public function userAgreement(){
        if(Request::instance()->isPost()){
            $userAgreement = input('userAgreement');
            $res = Db::table('up_about_us')->where('about_id', 1)->update(['agreement' => $userAgreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about_us')->where('about_id', 1)->value('agreement');
        $this->assign('userAgreement', $agreement);
        return $this->fetch('agreement/useragreement');
    }
    
    /**
     * @return mixed|\think\response\Json
     * 编辑商家注册协议
     */
    public function shopAgreement(){
        if(Request::instance()->isPost()){
            $shopAgreement = input('shopAgreement');
            $res = Db::table('up_about_us')->where('about_id', 1)->update(['shop_agreement' => $shopAgreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about_us')->where('about_id', 1)->value('shop_agreement');
        $this->assign('shopAgreement', $agreement);
        return $this->fetch('agreement/shopagreement');
    }
    /**
     * @return mixed|\think\response\Json
     * 编辑商家隐私协议
     */
    public function shopyinsi(){
        if(Request::instance()->isPost()){
            $shopAgreement = input('shopAgreement');
            $res = Db::table('up_about_us')->where('about_id', 2)->update(['about_us' => $shopAgreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about_us')->where('about_id', 2)->value('about_us');
        $this->assign('shopAgreement', $agreement);
        return $this->fetch('agreement/shopyinsi');
    }
    
    /**
     * @return mixed|\think\response\Json
     * 商家发布活动协议
     */
    public function taskAgreement(){
        if(Request::instance()->isPost()){
            $taskAgreement = input('taskAgreement');
            $res = Db::table('up_about_us')->where('about_id', 1)->update(['task_agreement' => $taskAgreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about_us')->where('about_id', 1)->value('task_agreement');
        $this->assign('taskAgreement', $agreement);
        return $this->fetch('agreement/taskagreement');
    }
}